home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 5 / MacMania 5.toast / / Tools&Utilities / Plotfoil 3.2 / nacafix.pl < prev    next >
Perl Script  |  1995-09-18  |  946b  |  49 lines

  1. #!/usr/local/bin/perl
  2.  
  3. # convert data in old NACA format
  4. #          Clark YH
  5. #          0 0 0
  6. #          0.0125 0.0409 -0.0183
  7. #          0.025 .0529 -.0271
  8. #          ...
  9. #          1.0 0 0
  10. # to the new (Soartech 8) format.
  11. #          SD-8020
  12. #          1.0 0
  13. #          0.9 0.011
  14. #          0.85 0.02
  15. #          ...
  16. #          1.0 0
  17. #
  18.  
  19. $tmpfile = "tmp-nacafix-$$";
  20.  
  21. foreach $filename (@ARGV) {
  22.  
  23.     next if(! -f $filename);
  24.  
  25.     open(INFILE, $filename);
  26.     open(OUTFILE, ">$tmpfile");
  27.     print OUTFILE scalar <INFILE>;
  28.     $i = 0;
  29.     while(<INFILE>) {
  30.         ($x, $lower, $upper) = split(' ');
  31.         $upper{$i} = $x . " " . $upper . "\n";
  32.         $lower{$i} = $x . " " . $lower . "\n";
  33.         $i++;
  34.     }
  35.     $n = $i;
  36.     $_ = "";
  37.     for(; $i >= 0; $i--) {
  38.         print OUTFILE  $upper{$i};
  39.     }
  40.     $i = 0;
  41.     $i++ if($upper{$i} eq $lower{$i});
  42.     for(; $i < $n; $i++) {
  43.         print OUTFILE $lower{$i};
  44.     }
  45.     close(INFILE); close(OUTFILE);
  46.     rename($filename, $filename . ".bak");
  47.     rename($tmpfile, $filename);
  48. }
  49.